package org.zpmis.domain.label.vo;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.zpmis.domain.label.model.Label;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class LabelVo{
    /**
     * 主键id
     */
    @ExcelIgnore
    private Long id;

    /**
     * 订单号
     */
    @ExcelIgnore
    private String orderNum;

    /**
     * 企业id
     */
    @ExcelIgnore
    private Long companyId;

    /**
     * 使用企业名称
     */
    @ExcelProperty(value = "使用企业名称",index = 0)
    @ColumnWidth(40)
    private String companyName;

    /**
     * 产品名称
     */
    @ColumnWidth(22)
    @ExcelProperty(value = "产品名称",index = 1)
    private String productName;

    /**
     * 标签数量
     */
    @ColumnWidth(22)
    @ExcelProperty(value = "标签数量",index = 2)
    private Long labelNum;

    /**
     * 开始号段
     */
    @ColumnWidth(22)
    @ExcelProperty(value = "开始号段",index = 3)
    //@ContentStyle(quotePrefix = true)//把数字转换成文本
    //@ContentFontStyle
    private String startSegment;

    /**
     * 结束号段
     */
    @ColumnWidth(22)
    @ExcelProperty(value = "结束号段",index = 4)
    //@ContentStyle(quotePrefix = true)//把数字转换成文本
    private String endSegment;

    /**
     * 标签类型 1箱标 2号段
     */
    @ExcelIgnore
    private Integer labelType;
    /**
     * 使用方式 1凭证 2号段
     */
    @ColumnWidth(22)
    @ExcelProperty(value = "使用方式",index = 5,converter = LabelUseModelConverter.class)
    private Integer useMode;

    /**
     * 激活状态 0未激活 1已激活 2客户激活 3等通知 4作废
     */
    @ColumnWidth(22)
    @ExcelProperty(value = "激活状态",index = 6,converter = LabelActiveStatusConverter.class)
    private Integer activeStatus;

    /**
     * 生成时间
     */
    @ColumnWidth(22)
    @ExcelProperty(value = "生成时间",index = 7)
    private String generationTime;

    /**
     * 印刷凭证企业名称
     */
    @ColumnWidth(40)
    @ExcelProperty(value = "印刷凭证企业名称",index = 8)
    private String printVoucherCompanyName;

    /**
     * 印刷凭证时间
     */
    @ExcelIgnore
    private String printVoucherTime;

    /**
     * 申请人
     */
    @ColumnWidth(40)
    @ExcelProperty(value = "申请人",index = 9)
    private String applyPeople;

    /**
     * 申请人id
     */
    @ExcelIgnore
    private Long applyId;

    /**
     * 备注
     */
    @ColumnWidth(22)
    @ExcelProperty(value = "备注",index = 10)
    private String remark;

    /**
     * 记录创建时间
     */
    @ExcelIgnore
    private String createTime;

    /**
     * 记录修改时间
     */
    @ExcelIgnore
    private String updateTime;

    /**
     * 是否删除 0未删除 1 已删除
     */
    @ExcelIgnore
    private Integer isDeleted;

    public LabelVo(Label label) {
        this.id = label.getId();
        this.orderNum = label.getOrderNum();
        this.companyId = label.getCompanyId();
        this.companyName = label.getCompanyName();
        this.productName = label.getProductName();
        this.labelNum = label.getLabelNum();
        this.startSegment = label.getStartSegment();
        this.endSegment = label.getEndSegment();
        this.labelType = label.getLabelType();
        this.useMode = label.getUseMode();
        this.activeStatus = label.getActiveStatus();
        this.generationTime = label.getGenerationTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(label.getGenerationTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.printVoucherTime = label.getPrintVoucherTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(label.getPrintVoucherTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.printVoucherCompanyName = label.getPrintVoucherCompanyName();
        this.applyPeople = label.getApplyPeople();
        this.applyId = label.getApplyId();
        this.remark = label.getRemark();
        this.createTime = label.getCreateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(label.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.updateTime = label.getUpdateTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(label.getUpdateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.isDeleted = label.getIsDeleted();
    }
}